package com.unimas.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.unimas.bean.User;
import com.unimas.dof.util.JsonUtil;

public class Testjson {
	public static void main(String[] args) {
		System.out.println("Object >> Json");
		objectToJson();
		
		System.out.println("list >> Json");
		listToJson();
		
		System.out.println("map >> Json");
		mapToJson();
		
		System.out.println("array >> Json");
		arrayToJson();
		
	}
	
	public static void objectToJson(){
		User user = new User();
		user.setId(1);
		user.setName("dengm");
		user.setEmail("dengm@uniamssystem.com");
		String objtojson = JsonUtil.objToJson(user);
		System.out.println(objtojson);
	}
	
	public static void listToJson(){
		User user = new User();
		user.setId(1);
		user.setName("dengm");
		user.setEmail("dengm@uniamssystem.com");
		List list = new ArrayList();
		list.add("admin");
		list.add(1);
		list.add(2.3);
		list.add(true);
		list.add(false);
		list.add(user);
		String listtojson = JsonUtil.listToJson(list);
		System.out.println(listtojson);
	}
	
	public static void mapToJson(){
		List ll = new ArrayList();
		for(int i=0; i<5; i++){
			User u = new User();
			u.setId(i);
			u.setName("user-"+i);
			u.setEmail(i+"@unimassystem.com");
			ll.add(u);
		}
		User user = new User();
		user.setId(1);
		user.setName("dengm");
		user.setEmail("dengm@uniamssystem.com");
		Map map = new HashMap();
		map.put("success", false);
		
		map.put("data", ll);
		map.put("entry", user);
		System.out.println(JsonUtil.mapToJson(map));
	}
	
	public static void arrayToJson(){
		String names[] = {"dengm","unimas","admin","system"};
		System.out.println(JsonUtil.arrayToJson(names));
		
	}
}
